<template>
  <div style="margin: 1rem">
    <!--  搜索框-->
    <div>
      <el-row :gutter="15">
        <el-col :span="6">
          <div>
            <search title="用户" :url="ListByUser" :table-fields="ListByUserFidles" allowCheck="1" :index="gzwl002"
                    ref="gzwl002"></search>
          </div>
        </el-col>
        <el-col :span="6">
          <div>
            <search title="ip" :url="listByIp" :table-fields="listByIpFidles" allowCheck="1" :index="gzwl006"
                    ref="gzwl006"></search>
          </div>
        </el-col>
        <el-col :span="4">
          <div>
            <el-button type="primary" @click="loadTable">查找</el-button>
          </div>
        </el-col>
        <el-col :span="4">
          <div>
            <span>在线用户数：{{ total }}</span>
          </div>
        </el-col>
      </el-row>
    </div>
    <!--  表单-->
    <el-table
        :data="leftTableData"
        style="width: 100%"
        size="mini"
        border
        lazy
        v-loading="loading"
        row-key="rownum"
        :load="loadTable"
        :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
      <el-table-column
          prop="gzwl002"
          label="用户"
          width="180">
      </el-table-column>
      <el-table-column
          prop="gzwl006"
          label="IP"
          width="180">
      </el-table-column>
      <el-table-column
          prop="gzwl003"
          label="作业">
      </el-table-column>
      <el-table-column
          prop="gzwl004"
          label="开始时间">
      </el-table-column>
      <el-table-column
          prop="gzwl008"
          label="PID">
      </el-table-column>
      <el-table-column>
        <template scope="scope">
          <el-button type="danger" @click="kill(scope.row)">结束</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
        :v_show="total >0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="loadTable"
    />
    <div>
    </div>
  </div>
</template>

<script>
import {findListByUser, findListByIp, findList, findListInfo, killPrcoess} from '@/api/system/killProcess';

export default {
  name: "kill",
  data() {
    return {
      total: 0,
      leftTableData: [],
      listFields: [],
      ListByUser: findListByUser,
      gzwl002: 'gzwl002',
      listByIp: findListByIp,
      gzwl006: 'gzwl006',
      ListByUserFidles: [{label: '用户名', prop: 'gzwl002'}],
      listByIpFidles: [{label: 'IP', prop: 'gzwl006'}],
      leftTableFields: [{label: '用户', prop: 'gzwl002'}, {label: 'IP', prop: 'gzwl006'}],
      queryParams: {
        gzwl002: '',
        gzwl006: '',
        gzwl008: '',
        pageNum: 1,
        pageSize: 10,
      },
      killList: [],
      loading: false,
    }
  },
  mounted() {
    this.loadTable()
  },
  methods: {
    kill(row) {
      this.killList = []
      if ('children' in row) {
        for (let i in row.children) {
          this.killList = [...this.killList, row.children[i]]
        }
      } else {
        this.killList = [...this.killList, row]
      }
      killPrcoess(this.killList).then(resp => {
        if (resp.code == '200') {
          this.$message.success(resp.msg)
        }
      })
      setTimeout(this.loadTable, 1500)
    },
    loadTable() {
      this.loading = true
      this.queryParams.gzwl002 = this.$refs.gzwl002.queryParams.keyword
      this.queryParams.gzwl006 = this.$refs.gzwl006.queryParams.keyword
      findList(this.queryParams).then(resp => {
        if (resp.code == '200') {
          this.leftTableData = resp.rows
          this.total = resp.total
          this.loading = false
        }
      })
    },
  },
}
</script>

<style scoped>

</style>
